package com.rosense.srpingboot.utils;

import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.Random;

import org.springframework.util.ResourceUtils;

import net.dotool.IoTools;

/**
 * 
 * @author 李岩飞
 * @email eliyanfei@126.com
 * 2018年3月10日 上午10:34:11
 */
public class EchartsUtils {
	public static String buildEcharts(String name, Map<String, Object> dataMap) {
		final StringBuilder sb = new StringBuilder();
		try {
			/*读取配置文件*/
			File file = ResourceUtils.getFile("classpath:static/echarts/demo/" + name + ".txt");
			List<String> list = IoTools.readFromTxt(file);
			for (String s : list) {
				sb.append(s);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		String data = sb.toString();
		dataMap.put("index", new Random().nextInt(100000));
		for (String key : dataMap.keySet()) {
			data = data.replace("$" + key, String.valueOf(dataMap.get(key)));
		}
		return data;
	}
}
